package control;

import java.io.IOException;

import javax.portlet.*;

import form.BaseForm;
import form.LoginForm;

public class Login extends BaseControl {
	/**
	 * this fucntion will be call when user submit on login form.
	 * the form will pass to LoginForm control class username and password
	 * @param request get username and password
	 * @param response
	 * @return no return here
	 * @throws PortletException
	 * @throws IOException
	 */
	public LoginForm procLogin(ActionRequest request, ActionResponse response)
			throws PortletException, IOException {
		LOG.debug("procLogin.START");
		String user = request.getParameter("loginUsername");
		String pass = request.getParameter("loginPassword");
		//check username and password
		dao.UsersDAO loginUser = new dao.UsersDAO();
		int role = loginUser.login(user, pass);
		LoginForm result = new LoginForm();
		result.setLoginUsername(user);
		result.setRole(role);
		
		return result;
	}

	public BaseForm procBack(ActionRequest request, ActionResponse response)
			throws PortletException, IOException {
		LOG.debug("procBack.START");
		LOG.debug("procBack.START");
		return null;
	}
}
